/**
 * 详情对话框
 */
var TExhaustOutletInfoDlg = {
    data: {
        dischargeTubeName: "",
        dischargeTubeNumber: "",
        dischargeTubePosition: "",
        dischargeTubeHeight: "",
        dischargeTubeDiameter: "",
        pollutantsType: "",
        emissionStandards: "",
        // treatmentId: "",
        treatmentName: "",
        emissionLimit:"",
        isInside:"",
        isOrganization:""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();




    /*监听污染物种类*/
    var ajax1 = new $ax(Feng.ctxPath + "/tDict/pollutantsTypeList");
    var typeList = ajax1.start();
    console.log(typeList);
    for (var i = 0 ; i < typeList.length ; i++){
        $("select#pollutantsType").append("<option value=\"" + typeList[i].dictId + "\">" + typeList[i].name + "</option>");
    }
    //重新渲染
    layui.form.render("select");


    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/tExhaustOutlet/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();

    if (result.data.isOrganization!=null&&result.data.isOrganization!=""){
        var  sb = document.getElementById("isOpen");
        var  nb = document.getElementById("isShow");
        if(result.data.isOrganization == 1){
            sb.style.display = "none"
            nb.style.display = "block"
        } else if(result.data.isOrganization == 2) {
            nb.style.display = "none"
            sb.style.display = "block"
        }
    }
    form.val('tExhaustOutletForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/tExhaustOutlet/editItem", function (data) {
            if(data.code == 200) {
                Feng.success("更新成功！");
            }else{
                Feng.error("更新失败！" + data.message)
            }

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.message)
        });
        console.log(document.getElementById("pollutantsType"))
        data.field.pollutantsType = $('#pollutantsType').val()
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //监听有无组织

    form.on('select(isOrganization)', function (data) {
         $('#isOrganization').attr("disabled","disabled");
        console.log(data.elem); //得到select原始DOM对象
        console.log(data.value); //得到被选中的值
        console.log(data.othis); //得到美化后的DOM对象
        var  sb = document.getElementById("isOpen");
        var  nb = document.getElementById("isShow");
        console.log(sb); //得到select原始DOM对象
        if (data.value == 1) {
            sb.style.display = "none"
            // sb.attributes.getNamedItem("required").value = false;
            nb.style.display = "block"
            // $('#reasons').style.display ="none";
        }else {
            sb.style.display = "block"
            nb.style.display = "none"
        }
    });

});